import { doubleValidate, mapVerification } from "~/utils/validate.js";
import {
    getAllProject,
    getAddress
} from "~/views/property-info-sys/project-manage/api/project_manage";
import uploadMedia from "@/components/upload-media";
import {
    save,
    get,
    update,
    getLandInfo
} from "~/views/property-info-sys/building-manage/api/building";
import { setProperty } from "~/utils";
import dbl from "@/utils/dbl";
import positionDialog from "@/components/positionDialog";
import { mapGetters } from "vuex";
import moment from "moment";

export default {
    components: {
        uploadMedia,
        positionDialog
    },
    computed: {
        /*selectProvice: function (){
            return this.provinces.find(p => p.value == this.propForm.building.provinceCode)
        },
        selectCity: function(){
            return this.citys.find(p => p.value == this.propForm.building.cityCode)
        },
        selectCounty: function(){
            return this.countys.find(p => p.value == this.propForm.building.countyCode)
        },
        chArea: function() {
            let p = this.selectProvice? this.selectProvice.label : ''
            let c = this.selectCity? this.selectCity.label : ''
            let y = this.selectCounty ? this.selectCounty.label : ''
            return  p + c + y
        },*/
        // hxf-0903-文件上传请求头
        headers: () => {
            return {
                Authorization: dbl.get("token")
            };
        },
        ...mapGetters({
            cityAssembly: "getCityAssembly",
            districtCollection: "getDistrictCollection"
        })
    },
    created() {
        let routeParamId = this.$route.query.id;
        this.projectId = this.$route.query.projectId;
        this.current = this.$route.query.current;
        if (routeParamId) {
            this.isAdd = false;
            this.id = routeParamId;
            this.initCitySelector();
        }
        this.landUses = this.getDict("land_uses");
        if (this.current === "10") {
            this.handleGetLandInfo(1);
        } else {
            this.handleGetLandInfo(1);
        }
        this.propForm.building.cityCode = this.cityAssembly[0].value;
    },
    mounted() {
        if (this.isAdd) {
            // this.queryProvince()
        }
        getAllProject().then(rep => {
            let repData = rep.data.data;
            let allProject = repData.map(p => {
                if (p.acceptanceTime) {
                    return {
                        value:
                            p.projectId +
                            "#" +
                            moment(p.acceptanceTime).format("YYYY-MM-DD"),
                        label: p.projectName
                    };
                } else {
                    return { value: p.projectId + "#", label: p.projectName };
                }
            });
            this.allProject = allProject;
        });
        this.communityNames = this.getDict("community_names");
        this.streets = this.getDict("streets");
        this.manageUnits = this.getDict("administrative_office");
    },
    data() {
        let isInt = (rule, value, callback) => {
            if (!value) {
                callback();
            }
            const re = /^(0|[1-9][0-9]*)$/;
            const rsCheck = re.test(value);
            if (!rsCheck) {
                callback(new Error("请输入0或大于0的整数"));
            } else {
                if (value > 99999) {
                    return callback(new Error("最大值不超过99999"));
                } else {
                    callback();
                }
            }
        };
        return {
            current: "10",
            loading: true,
            isAdd: true,
            projectId: "",
            id: "",
            oldGroundTotal: "",
            oldUndergroundFloors: "",
            oldFloors: "",
            canUpdate: false,
            canSetFloor: false,
            belongs: [],
            provinces: [],
            citys: [],
            countys: [],
            allProject: [],
            manageUnits: [],
            selectProject: "",
            communityNames: [],
            communityNameStreet: [],
            streets: [],
            landUses: [],
            propForm: {
                building: {
                    buildingName: "",
                    buildingCode: "",
                    unitNum: "",
                    projectId: "",
                    completeTime: "",
                    roomType: "",
                    buildPrice: "",
                    geographicCoordinates: "",
                    groundArea: "",
                    undergroundArea: "",
                    totalSets: "",
                    floorArea: "",
                    areaCode: "",
                    provinceCode: "",
                    cityCode: "",
                    countyCode: "",
                    address: "",
                    isDetachedHouse: "0",
                    unitBuilding: "0",
                    groundFloors: "2",
                    undergroundFloors: "",
                    totalFloors: "",
                    remarks: "",
                    selectProject: "",
                    communityName: "",
                    buildStreet: "",
                    manageUnit: "",
                    areaName: ""
                },
                facilitiesName: "",
                projectName: "",
                floors: [],
                buildingFloor: {
                    totalFloors: "",
                    undergroundFloors: "",
                    groundFloors: ""
                }
            },
            landInfo: {
                address: "",
                addressInfo: "",
                landContractNum: "",
                landId: "",
                landUse: "",
                parcelArea: "",
                parcelNum: "",
                remarks: ""
            },
            floor_rules: {},
            buildingFloor_rules: {
                groundFloors: [
                    {
                        required: true,
                        message: "请输入地上层数",
                        trigger: "blur"
                    }
                ],
                undergroundFloors: [
                    {
                        required: true,
                        message: "请输入地下层数",
                        trigger: "blur"
                    }
                ],
                totalFloors: [
                    { required: true, message: "请输入总层数", trigger: "blur" }
                ]
            },
            floors_rules: {
                floorNum: [
                    { required: true, message: "请输入层号", trigger: "blur" },
                    {
                        min: 0,
                        max: 10,
                        message: "长度在0-10个字符串",
                        trigger: "blur"
                    }
                ],
                actualFloor: [
                    { required: true, message: "请输入实际层", trigger: "blur" }
                ],
                nominalFloor: [
                    {
                        required: true,
                        message: "请输入名义层",
                        trigger: "blur"
                    },
                    {
                        min: 0,
                        max: 10,
                        message: "长度在0-10个字符串",
                        trigger: "blur"
                    }
                ],
                buildingArea: [
                    {
                        required: true,
                        message: "请输入层建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                insideArea: [
                    {
                        required: true,
                        message: "请输入层套内面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                insideBuildingArea: [
                    {
                        required: true,
                        message: "请输入层套内建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                contributionArea: [
                    {
                        required: true,
                        message: "请输入层分摊建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                floorHeight: [
                    { required: true, message: "请输入层高", trigger: "blur" },
                    { validator: doubleValidate, trigger: "blur" }
                ]
            },
            building_rules: {
                buildingName: [
                    {
                        required: true,
                        message: "请输入楼栋名称",
                        trigger: "blur"
                    },
                    {
                        min: 0,
                        max: 30,
                        message: "长度在0-30个字符串",
                        trigger: "blur"
                    }
                ],
                unitNum: [
                    {
                        required: true,
                        message: "请输入不动产单元号",
                        trigger: "blur"
                    },
                    {
                        min: 0,
                        max: 30,
                        message: "长度在0-30个字符串",
                        trigger: "blur"
                    }
                ],
                projectId: [
                    {
                        required: true,
                        message: "请选择所属项目",
                        trigger: "blur"
                    }
                ],
                selectProject: [
                    {
                        required: true,
                        message: "请选择所属项目",
                        trigger: "blur"
                    }
                ],
                completeTime: [
                    {
                        required: true,
                        message: "请选择竣工时间",
                        trigger: "blur"
                    }
                ],
                roomType: [
                    {
                        required: true,
                        message: "请输入房屋性质",
                        trigger: "blur"
                    },
                    {
                        min: 0,
                        max: 20,
                        message: "长度在0-30个字符串",
                        trigger: "blur"
                    }
                ],
                buildPrice: [
                    {
                        required: false,
                        message: "请输入建构价数",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                geographicCoordinates: [
                    {
                        required: false,
                        message: "请输入地图坐标",
                        trigger: "blur"
                    },
                    {
                        min: 0,
                        max: 50,
                        message: "长度在0-50个字符串",
                        trigger: "blur"
                    },
                    { validator: mapVerification, trigger: "blur" }
                ],
                groundArea: [
                    {
                        required: false,
                        message: "请输入地上建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                undergroundArea: [
                    {
                        required: false,
                        message: "请输入地下建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                floorArea: [
                    {
                        required: true,
                        message: "请输入建筑面积",
                        trigger: "blur"
                    },
                    { validator: doubleValidate, trigger: "blur" }
                ],
                totalSets: [
                    {
                        required: false,
                        message: "请输入总套数",
                        trigger: "blur"
                    },
                    { validator: isInt, trigger: "blur" }
                ],
                /*provinceCode: [
                    { required: true, message: "请选择地址", trigger: "blur" },
                ],*/
                cityCode: [
                    {
                        required: true,
                        message: "请选择地址",
                        validator: (rules, value, callback) => {
                            //区县
                            let county = this.propForm.building.countyCode;
                            //   街道
                            let street = this.propForm.building.buildStreet;
                            //   社区
                            let community = this.propForm.building
                                .communityName;
                            //   道路及门牌号
                            let address = this.propForm.building.address;
                            if (
                                !value ||
                                !county ||
                                !street ||
                                !community ||
                                !address
                            ) {
                                return callback(new Error("物业地址不能为空"));
                            }
                            return callback();
                        },
                        trigger: "blur"
                    }
                ]
                /*countyCode: [
                    { required: true, message: "请选择地址", trigger: "blur" },
                ],
                buildStreet: [
                    { required: true, message: "请选择街道", trigger: "blur" },
                ],
                communityName: [
                    { required: true, message: "请选择社区", trigger: "blur" },
                ],
                manageUnit: [
                    { required: true, message: "请选择管理权属", trigger: "blur" },
                ],*/
            },
            //  hxf-0903-文件自动上传
            modelType: "operate",
            /*dialogImageUrl: '',
            dialogVisible: false,
            disabled: false,
            tips: '上传图片：支持扩展名：jpg、jpeg、png、gif、bmp',
            // hxf-0903-文件展示列表
            loadFileList: [],*/
            busId: ""
        };
    },
    watch: {
        //    Number(this.propForm.buildingFloor.groundFloors) + Number(this.propForm.buildingFloor.undergroundFloors)
        "propForm.buildingFloor.groundFloors": function(newVal, oldVal) {
            let total = this.propForm.buildingFloor.totalFloors;
            if (total) {
                this.propForm.buildingFloor.totalFloors =
                    Number(newVal) +
                    Number(this.propForm.buildingFloor.undergroundFloors);
            } else {
                this.propForm.buildingFloor.totalFloors = newVal;
            }
        },
        "propForm.buildingFloor.undergroundFloors": function(newVal, oldVal) {
            let total = this.propForm.buildingFloor.totalFloors;
            if (total) {
                this.propForm.buildingFloor.totalFloors =
                    newVal + Number(this.propForm.buildingFloor.groundFloors);
            } else {
                this.propForm.buildingFloor.totalFloors = newVal;
            }
        }
    },
    methods: {
        // 修改时初始化地址选择器
        async initCitySelector() {
            const loading = this.$loading({
                lock: true,
                text: "数据加载中"
            });
            await get(this.id)
                .then(rep => {
                    this.isAdd = false;
                    if ("1" === rep.data.data.canUpdate) {
                        this.canUpdate = true;
                    }

                    this.propForm.building = rep.data.data.building;
                    // this.propForm.floors = rep.data.data.floors;
                    this.propForm.floors = rep.data.data.floors;
                    this.propForm.facilitiesName = rep.data.data.facilitiesName;
                    this.propForm.projectName = rep.data.data.projectName;
                    this.propForm.building.selectProject =
                        rep.data.data.projectName;
                    this.propForm.building.cityCode = this.propForm.building.areaCode.split(
                        "-"
                    )[0];
                    this.propForm.building.countyCode = this.propForm.building.areaCode.split(
                        "-"
                    )[1];
                    if (
                        rep.data.data.floors !== undefined &&
                        rep.data.data.floors.length > 0
                    ) {
                        this.$nextTick(() => {
                            this.getFiles(0);
                        });
                    }

                    setProperty(
                        this.propForm.buildingFloor,
                        this.propForm.building
                    );
                    //初始化项目名称、地区选择
                    // this.propForm.building.selectProject = this.propForm.building.projectId + '#' + this.propForm.building.completeTime
                    /*if(this.propForm.building.areaCode){
                    let area = this.propForm.building.areaCode.split("-")
                    if(area.length == 3){
                        this.propForm.building.provinceCode = area[0]
                        this.propForm.building.cityCode = area[1]
                        this.propForm.building.countyCode = area[2]
                    }
                }*/
                    //记录原始的层数
                    this.oldGroundTotal = this.propForm.buildingFloor.groundFloors;
                    //记录原始的层数(地下)
                    this.oldUndergroundFloors = this.propForm.buildingFloor.undergroundFloors;

                    if (!this.propForm.buildingFloor.undergroundFloors) {
                        this.canSetFloor = true;
                    }

                    //记录原始的层信息
                    this.oldFloors = this.propForm.floors;
                    //获取省市县区下拉数据
                    /*this.queryProvince();
                if(this.propForm.building.provinceCode){
                    this.queryCitys(this.propForm.building.provinceCode)
                }
                if(this.propForm.building.cityCode){
                    this.queryCounty(this.propForm.building.cityCode)
                }*/
                    //添加街道社区级联
                    this.initCommunityName();
                    loading.close();
                })
                .catch(e => {
                    console.log(e);
                    loading.close();
                    this.$message.error("数据获取失败!");
                });
        },
        undergroundGenerateFloor() {
            if (
                !this.propForm.buildingFloor.undergroundFloors ||
                !Number(this.propForm.buildingFloor.undergroundFloors) ||
                Number(this.propForm.buildingFloor.undergroundFloors) > 20 ||
                Number(this.propForm.buildingFloor.undergroundFloors) < 0
            ) {
                this.propForm.buildingFloor.undergroundFloors = 0;
                this.$message.error("地下层数只能是正整数且不大于20！");
            }
            //获取地下层数
            let groundTotal = this.propForm.buildingFloor.undergroundFloors;

            let startIndex = 1;
            let floorsUnder = this.propForm.floors.filter(
                r => r.actualFloor < 0
            );

            if (!this.isAdd && this.oldUndergroundFloors > groundTotal) {
                this.propForm.buildingFloor.undergroundFloors = this.oldUndergroundFloors;
                this.propForm.floors = this.oldFloors;
                //数组切割成原始值
                this.$message.error("地下层数不能小于上一次变更的值！");
                return;
            }

            //与上次一比如果是增加层数，则在原有数组基础上添加新的值，保证已填写数据不丢失
            if (groundTotal > floorsUnder.length) {
                startIndex = floorsUnder.length + 1;
            }
            //如果是减少层数，则将原有数据截取
            if (groundTotal < floorsUnder.length) {
                floorsUnder.splice(0, floorsUnder.length - groundTotal);
                startIndex = floorsUnder.length + 1;
            }
            //清空地下层数组
            for (let i = groundTotal; i >= startIndex; i--) {
                floorsUnder.push({
                    floorId: "",
                    buildingId: "",
                    floorNum: "",
                    actualFloor: -i,
                    nominalFloor: "",
                    buildingArea: "",
                    insideArea: "",
                    floorHeight: "",
                    picUrl: "",
                    orderNum: "",
                    contributionArea: "",
                    insideBuildingArea: "",
                    uploadFileList: []
                });
            }
            //排序
            floorsUnder.sort(
                (a, b) => Math.abs(b.actualFloor) - Math.abs(a.actualFloor)
            );

            let upFloors = this.propForm.floors.filter(r => r.actualFloor > 0);
            this.propForm.floors = floorsUnder.concat(upFloors);
        },
        generateFloor() {
            if (
                !this.propForm.buildingFloor.groundFloors ||
                !Number(this.propForm.buildingFloor.groundFloors) ||
                Number(this.propForm.buildingFloor.groundFloors) > 200 ||
                Number(this.propForm.buildingFloor.groundFloors) < 0
            ) {
                this.propForm.buildingFloor.groundFloors = 0;
                this.$message.error("地上层数只能是正整数且不大于200！");
            }
            //地上
            let groundTotal = this.propForm.buildingFloor.groundFloors;

            //得到地上楼层数组
            let floors = this.propForm.floors.filter(r => r.actualFloor > 0);
            if (!this.isAdd && this.oldGroundTotal > groundTotal) {
                this.propForm.buildingFloor.groundFloors = this.oldGroundTotal;
                this.propForm.floors = this.oldFloors;
                //数组切割成原始值
                this.$message.error("地上层数不能小于上一次变更的值！");
                return;
            }

            //地上起始位置
            let startIndex = 1;
            //如果变动后的层数比变动前的层数高，则在原有层数基础上增加数组长度
            if (groundTotal >= floors.length) {
                startIndex = floors.length + 1;
            }
            //如果变动后的数组长度小于原有长度,则需要截取原有长度
            if (groundTotal < floors.length) {
                startIndex = groundTotal + 1;
                floors.splice(groundTotal, floors.length - groundTotal);
            }
            // //清空数组
            // this.propForm.floors.length = 0

            for (let i = startIndex; i <= groundTotal; i++) {
                floors.push({
                    floorId: "",
                    buildingId: "",
                    floorNum: "",
                    actualFloor: i,
                    nominalFloor: "",
                    buildingArea: "",
                    insideArea: "",
                    floorHeight: "",
                    picUrl: "",
                    orderNum: "",
                    contributionArea: "",
                    insideBuildingArea: "",
                    uploadFileList: []
                });
            }
            //将组装好的地上楼层信息拼接到数组中
            let dowFloors = this.propForm.floors.filter(r => r.actualFloor < 0);
            this.propForm.floors = dowFloors.concat(floors);
        },
        /*queryProvince(){
            getDivision({"lazy": true, parentId: "000000"}).then(rep => {
                let rep_province = rep.data.data
                this.provinces = rep_province.map(p => {
                    return {"label": p.divisionName, "value": p.divisionCode}
                })
            })
        },
        //获取城市
        queryCitys(val){
            getDivision({"lazy": true, parentId: val}).then(rep => {
                let rep_city = rep.data.data
                this.citys = rep_city.map(p => {
                    return {"label": p.divisionName, "value": p.divisionCode}
                })

            })
        },
        //获取县区
        queryCounty(val){
            getDivision({"lazy": true, parentId: val}).then(rep => {
                let rep_county = rep.data.data
                this.countys = rep_county.map(p => {
                    return {"label": p.divisionName, "value": p.divisionCode}
                })
            })
        },*/

        submitForm() {
            //验证单元楼座输入是否正确
            if (this.propForm.building.unitBuilding == 1) {
                this.validateUnitSize();
                if (!this.propForm.building.unitSize) {
                    this.$message.error("请输入单元/楼座信息");
                    return false;
                }
            }

            //多表单同步验证 Promise
            /*this.propForm.building.areaCode = this.propForm.building.provinceCode +
                    "-" + this.propForm.building.cityCode +
                    "-" + this.propForm.building.countyCode*/
            this.propForm.building.areaCode =
                this.propForm.building.cityCode +
                "-" +
                this.propForm.building.countyCode;
            this.propForm.building.areaName =
                this.getCardTypeValue(
                    this.propForm.building.cityCode,
                    this.cityAssembly
                ) +
                this.getCardTypeValue(
                    this.propForm.building.countyCode,
                    this.districtCollection
                ) +
                this.getCardTypeValue(
                    this.propForm.building.buildStreet,
                    this.streets
                ) +
                this.getCardTypeValue(
                    this.propForm.building.communityName,
                    this.communityNames
                );
            // + this.propForm.building.address

            const building = new Promise((resolve, reject) => {
                this.$refs["building"].validate(valid => {
                    if (valid) resolve();
                });
            });
            const buildingFloor = new Promise((resolve, reject) => {
                this.$refs["buildingFloor"].validate(valid => {
                    if (valid) resolve();
                });
            });

            Promise.all([building, buildingFloor]).then(() => {
                //验证 建筑面积（必填）<=地上建筑面积（非必填）+地下建筑面积（非必填）

                let fArea = this.propForm.building.floorArea;
                let gArea = this.propForm.building.undergroundArea;
                let ugArea = this.propForm.building.groundArea;
                if (
                    (gArea || ugArea) &&
                    fArea &&
                    Number(fArea) - (Number(gArea) + Number(ugArea)) < 0
                ) {
                    this.$message.error(
                        "建筑面积不能大于地上建筑面积+地下建筑面积"
                    );
                    return false;
                }

                // validateProjectBuildNum(this.propForm.building.projectId, this.id).then(rep => {
                //     let pdata = rep.data.data
                //     if (pdata === 1) {
                //         this.$message.error("该项目楼栋数量已达到上限，不可再新增楼栋")
                //         this.propForm.building.selectProject=''
                //         return false;
                //     }else{
                const loading = this.$loading({
                    lock: true,
                    text: "数据保存中"
                });
                //加入VR
                if (this.propForm.building.vrUrl) {
                    this.propForm.building.isVr = "1";
                } else {
                    this.propForm.building.isVr = "0";
                }
                //对象合并
                Object.assign(
                    this.propForm.building,
                    this.propForm.buildingFloor
                );
                if (this.isAdd) {
                    save(this.propForm)
                        .then(rep => {
                            loading.close();
                            this.$message.success("保存成功");
                            this.closeNowRouter();
                        })
                        .catch(e => {
                            console.log(e);
                            loading.close();
                            this.$message.error("保存失败");
                        });
                } else {
                    update(this.propForm)
                        .then(rep => {
                            loading.close();
                            this.$message.success("修改成功");
                            this.closeNowRouter();
                        })
                        .catch(e => {
                            console.log(e);
                            loading.close();
                            this.$message.error("修改失败");
                        });
                }
                //     }
                // })
            });
        },
        closeNowRouter() {
            //关闭当前新增页，暂时没找到好办法
            this.$store.commit("delHistoryRoute", this.$route.fullPath);
            // this.$parent.$children[2].closeTab('current')
            //跳转
            sessionStorage.setItem("current", this.current);
            this.$router.push("/property-info-sys/building-manage");
        },

        changeProject(val) {
            if (val && val.indexOf("#") != -1) {
                let ps = val.split("#");
                //验证是否可新增
                // validateProjectBuildNum(ps[0]).then(rep => {
                //     let pdata = rep.data.data
                //     if(pdata === 1){
                //         this.$message.error("该项目楼栋数量已达到上限，不可再新增楼栋")
                //         this.propForm.building.selectProject=''
                //         return false;
                //     }else{
                this.propForm.building.projectId = ps[0];
                if (ps.length == 2 && ps[1] !== "") {
                    this.propForm.building.completeTime = ps[1];
                } else {
                    this.propForm.building.completeTime = "";
                }

                //获取项目的地址信息
                getAddress(ps[0]).then(rep => {
                    let pdata = rep.data.data;
                    if (pdata) {
                        //地图坐标
                        this.propForm.building.geographicCoordinates =
                            pdata.mapCoordinates;
                        this.propForm.building.address = pdata.addressInfo;
                        this.propForm.building.areaName = pdata.areaName;
                        //    省市县编码
                        if (
                            pdata.areaCode &&
                            pdata.areaCode.indexOf("-") != -1
                        ) {
                            let acode = pdata.areaCode.split("-");
                            this.propForm.building.cityCode = acode[0];
                            this.propForm.building.countyCode = acode[1];
                        }

                        //街道
                        this.propForm.building.buildStreet =
                            pdata.projectStreet;
                        this.propForm.building.manageUnit = pdata.manageUnit;
                        this.handleChangeStreet();
                        //社区
                        this.propForm.building.communityName =
                            pdata.communityName;
                        // this.queryCitys(pdata.provinceCode)
                        // this.queryCounty(this.propForm.building.cityCode)
                    }
                });
                //     }
                // })
            }
        },
        getFiles(index) {
            const ref = this.$refs.buildingFiles[index];
            ref.getFiles();
        },
        handleClick(tab) {
            this.busId = this.propForm.floors[tab.index].floorId;
            this.getFiles(tab.index);
        },
        // 监听地图坐标监听
        resetPosition(data) {
            let position = JSON.parse(data);
            if (position.length) {
                this.propForm.building.geographicCoordinates = position.join(
                    ","
                );
            }
        },
        // hxf-1009-区改变清空街道和社区
        handleChangeCountyCode() {
            this.propForm.building.buildStreet = "";
            this.propForm.building.communityName = "";
            this.$forceUpdate();
        },
        // hxf-1009-街道改变清空社区
        handleChangeStreet() {
            this.$forceUpdate();
            this.propForm.building.communityName = "";
            this.initCommunityName();
        },
        initCommunityName() {
            this.communityNameStreet.length = 0;
            let selectStreet = this.propForm.building.buildStreet;
            if (
                selectStreet != "" &&
                this.communityNames != null &&
                this.communityNames.length > 0
            ) {
                this.communityNameStreet = this.communityNames.filter(
                    cn => cn.value.indexOf(selectStreet) != -1
                );
            }
        },
        // hxf-1010-根据id获取土地信息
        handleGetLandInfo(type) {
            getLandInfo(type, this.projectId).then(res => {
                if (res.data.code === 0 && res.data.data !== null) {
                    this.landInfo = res.data.data;
                }
            });
        },
        // hxf-1010-回显时对应value显示label
        getCardTypeValue(num, sum) {
            let arr = sum.filter(e => e.value === num);
            if (arr.length > 0) {
                return arr[0].label;
            } else {
                return num;
            }
        },
        //jiaj 2020 12 17 添加
        validateUnitSize() {
            let value = this.propForm.building.unitSize;
            let reg = /^([1-9][0-9]*)$/;
            if (!reg.test(value)) {
                this.propForm.building.unitSize = "";
                return 1;
            } else {
                if (value > 100) {
                    this.propForm.building.unitSize = "";
                    return 2;
                }
            }
            return 0;
        },
        handleuUnitSize() {
            let vres = this.validateUnitSize();
            if (vres === 1) {
                this.$message.error("数值格式错误（请输入1-100之间的整数）");
                return;
            }
            if (vres === 2) {
                this.$message.error("最大值不超过100");
                return;
            }
        },
        handleInput(val, index) {
            this.$refs.buildingFiles[index].submit();
        },
        onSuccess(res, index) {
            if (res.data) {
                this.propForm.floors[index].floorId = res.data;
                this.$nextTick(() => {
                    this.$refs.buildingFiles[index].getFiles();
                });
            }
        }
    }
};
